//
//  MyViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/23.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "MyViewController.h"
#import "MyHeaderCell.h"
#import "MySecondCell.h"
#import "MyThirdCell.h"
#import "MyWalletViewController.h"
#import "ChangePhoneViewController.h"
#import "ChangeMessageViewController.h"
#import "PersonViewController.h"
#import "AdressMangerViewController.h"
#import "CarMangerViewController.h"
#import "AdviceViewController.h"
#import "MingXiViewController.h"
#import "QrCodeViewController.h"
#import "AboutViewController.h"
//二维码
#import "SYQRCodeViewController.h"
#import "SYQRCodeUtility.h"
static NSString *const text = @"https://";
static NSString *const MyHeaderCellID = @"MyHeaderCellID";
static NSString *const MySecondCellID = @"MySecondCellID";
static NSString *const MyThirdCellID = @"MyThirdCellID";
@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)NSArray *imageArr;//标题图片数组
@property (nonatomic,strong)NSArray *titleArr;//标题数组
@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleWithTitle:@"个人中心"];
    //变量初始化

    [self.view addSubview:self.tableV];
}
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.tabBarController.tabBar.hidden = NO;
}
//初始化标题数组
-(NSArray *)titleArr
{
    if(!_titleArr){
        _titleArr = @[@"我的钱包",
                      @"我的消费",
                      @"我的车辆",
                      @"我的地址",
                      @"常用联系人",
                      @"修改资料",
                      @"修改手机号",
                      @"意见反馈",
                      @"关于安安洗车",
                      @"",];
    }
    return _titleArr;
}
//初始化标题数组
-(NSArray *)imageArr
{
    if(!_imageArr){
        _imageArr = @[@"My_wallet",
                      @"My_xiaoFei",
                      @"My_car",
                      @"My_address",
                      @"My_person",
                      @"My_Change",
                      @"My_phone",
                      @"My_adv",
                      @"My_about",
                      ];
    }
    return _imageArr;
}
-(UITableView *)tableV
{
    if (!_tableV) {
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64-49) style:UITableViewStyleGrouped];
        _tableV.backgroundColor = backColor;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        [_tableV registerClass:[MyHeaderCell class] forCellReuseIdentifier:MyHeaderCellID];
        [_tableV registerClass:[MySecondCell class] forCellReuseIdentifier:MySecondCellID];
        [_tableV registerClass:[MyThirdCell class] forCellReuseIdentifier:MyThirdCellID];
        _tableV.delegate = self;
        _tableV.dataSource = self;
    }
    return _tableV;
}

#pragma Mark TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 80*screenW_6;
    }else if (indexPath.section == 1)
    {
        return 120*screenW_6;
    }else
    {
        return 50*screenW_6;
    }
}
//区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
//行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        return 5;
    }
    return 1;
}
//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0){
        return 5*screenW_6;
    }
    return 0.00001;
}
//区尾高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5*screenW_6;
}
//加载Cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {//头部自己的信息
        MyHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:MyHeaderCellID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setDataDic:nil];
        
        UITapGestureRecognizer *codeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(codeSelectTap)];
        [cell.codeImageV addGestureRecognizer:codeTap];
        return cell;
    }else if (indexPath.section == 1){//中间按钮
        MySecondCell *cell = [tableView dequeueReusableCellWithIdentifier:MySecondCellID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell loadCell:self.titleArr ImageArr:self.imageArr];
        cell.selectBlock = ^(NSInteger seletTag){
            if (seletTag == 0) {//我的钱包
                [self.navigationController pushViewController:[MyWalletViewController new] animated:YES];
            }else if (seletTag == 1){//我的消费
                [self.navigationController pushViewController:[MingXiViewController new] animated:YES];
            }
            else if (seletTag == 2){//我的车辆
                [self.navigationController pushViewController:[CarMangerViewController new] animated:YES];
            }
            else if (seletTag == 3){//我的地址
                [self.navigationController pushViewController:[AdressMangerViewController new] animated:YES];
            }
        };
        return cell;
    }else//底部cell按钮
    {
        MyThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:MyThirdCellID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell loadCellTitle:self.titleArr[indexPath.row+4] ImageArr:self.imageArr[indexPath.row+4]];
        return cell;
    }
 
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section == 2) {
        if (indexPath.row == 0) {//常用联系人
        [self .navigationController pushViewController:[PersonViewController new] animated:YES];
        }else if (indexPath.row == 1)//修改资料
        {
             [self .navigationController pushViewController:[ChangeMessageViewController new] animated:YES];
            
        }else if (indexPath.row == 2)//修改手机号
        {
            [self .navigationController pushViewController:[ChangePhoneViewController new] animated:YES];
        }
        else if (indexPath.row == 3)//意见反馈
        {
            [self .navigationController pushViewController:[AdviceViewController new] animated:YES];
        }
        else if (indexPath.row == 4)//关于安安洗车
        {
            [self .navigationController pushViewController:[AboutViewController new] animated:YES];
        }
    }
}

-(void)codeSelectTap
{
    __weak MyViewController *weakSelf = self;
    self.navigationController.tabBarController.tabBar.hidden = YES;
    SYQRCodeViewController *qrcodevc = [[SYQRCodeViewController alloc] init];
    qrcodevc.SYQRCodeSuncessBlock = ^(SYQRCodeViewController *aqrvc,NSString *qrString) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
    qrcodevc.SYQRCodeFailBlock = ^(SYQRCodeViewController *aqrvc) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
    qrcodevc.SYQRCodeCancleBlock = ^(SYQRCodeViewController *aqrvc) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
    [self.navigationController pushViewController:qrcodevc animated:YES];
}



@end

